class News {

	String title
	String caption
	String article
	String status
	Date publishStartDate
	Date publishEndDate

	static hasMany = [roles:Grole]
	static roleList = []
	    
	def List getRoleList() {
		def tempRoles = []
		roles.each{ r->
			//tempRoles.add(r.toString())
			tempRoles.add(r)
		}
		roleList = tempRoles
		roleList
	}


	static constraints = {
		publishStartDate(nullable:true)
		publishEndDate(nullable:true)
		article(maxSize:50000)
		status(inList:['writing','editing','published','suspended'])
	}

	def getNewsForRoles(roles) { 
		def allNews = []
		def news = News.findAll()
		roles.each { r->
println "checking role " + r
			news.each { n->
				n.roles.each { nr->
					println "news role = " + nr
					if(nr.toString()==r.toString()) { 
						println n.title
						println n.caption
						allNews << n
					}
				}
			}
		}
		allNews
	}
}
